<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>地图导航</title>
  <style>
        * {
          margin: 0;
          padding: 0;
        }
        #container {
          width: 100%;
          height: 100vh;
          background-color: pink;
        }

    </style>
</head>
<body>
<div id="container"></div>

<script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: "1407cf5116cbc5cf00ef192fe9e6acd7",
      };
</script>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=884994b3847b24760092896714f29dbf"></script>
<script type="text/javascript">
        var map = new AMap.Map("container", {
            zoom: 16, //级别
            center: [121.47592, 31.237687], //中心点坐标
        })


        function beginDriving(start,end){
            //引入和创建驾车规划插件
            AMap.plugin(["AMap.Driving"], function () {
              const driving = new AMap.Driving({
                map: map,
                //驾车策略，包括 LEAST_TIME，LEAST_FEE, LEAST_DISTANCE,REAL_TRAFFIC
                policy: AMap.DrivingPolicy.LEAST_TIME
              });
              //获取起终点规划线路
              var points = [{keyword: start},{keyword: end}]
              driving.search(points, function (status, result) {
                if (status === "complete") {
                  //status：complete 表示查询成功，no_data 为查询无结果，error 代表查询错误
                  //查询成功时，result 即为对应的驾车导航信息
                  console.log(result);
                } else {
                  console.log("获取驾车数据失败：" + result);
                }
              });
            });
        }

        //beginDriving("上海火车站","杭州东站")
</script>
</body>
</html>